package com.qianya.system.manage.web.login.controller;

import com.qianya.model.pojo.login.qo.LoginRoleInsertQO;
import com.qianya.system.manage.web.login.mapper.LoginRoleMapper;
import com.qianya.system.manage.web.login.model.LoginRole;
import com.qianya.system.manage.web.login.service.ILoginRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.qianya.model.common.CommonResult;
import com.qianya.model.pojo.login.qo.LoginRoleQO;
import com.qianya.model.pojo.login.vo.LoginRoleVO;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author wy
 * @since 2020-07-02
 */
@RestController
@RequestMapping("/login-role")
@Api(value = "LoginRoleController", tags = "角色接口")
@Slf4j
public class LoginRoleController {

    @Autowired
    private ILoginRoleService loginRoleService;


    @PutMapping("/update")
    @ApiOperation("修改角色")
    public CommonResult update(@RequestBody LoginRoleInsertQO loginRoleInsertQO) {
        return loginRoleService.renewal(loginRoleInsertQO);
    }

    @DeleteMapping("/delete")
    @ApiOperation("禁用/启用角色")
    public CommonResult deleteById(@ApiParam(value = "角色id",required = true)
                                       @NotBlank(message = "角色编号不能为空")
                                       @RequestParam(defaultValue = "",name = "roId")String roId) {
        return loginRoleService.deleteById(roId);
    }


    @PostMapping(value = "/save")
    @ApiOperation("添加角色")
    public CommonResult save(@Valid @RequestBody LoginRoleInsertQO loginRoleInsertQO) {
  return loginRoleService.create(loginRoleInsertQO);
    }

    @ApiOperation("查找所有角色")
    @GetMapping("/find")
    public CommonResult find(LoginRoleQO loginRoleQO) {
        return loginRoleService.find(loginRoleQO);
    }

    @ApiOperation("查找所有角色(无条件，不分页)")
    @GetMapping("/findAllRole")
    public CommonResult findAllRole(){
        return loginRoleService.findAllRole();
    }


    @ApiOperation(value = "根据id查找角色")
    @GetMapping(value = "/view")
    public CommonResult view(@ApiParam(value = "角色id", required = true)
                             @NotBlank(message = "角色编号不能为空")
                             @RequestParam(defaultValue = "", name = "roId") String roId) {
        return CommonResult.success(loginRoleService.view(roId));
    }
}
